#include "RingQueue.h"

void *pRoutine(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (1)
    {
        int data = rand() % 1000;
        rq->push(data);
    }
    return nullptr;
}

void *cRoutine(void *args)
{
    RingQueue<int> *rq = static_cast<RingQueue<int> *>(args);
    while (1)
    {
        sleep(2);
        int data = -1;
        rq->pop(data);
    }
    return nullptr;
}
int main()
{
    RingQueue<int> rq(6);
    pthread_t p1,p2,p3, c1,c2,c3,c4;
    pthread_create(&p1, nullptr, pRoutine, &rq);
    pthread_create(&p2, nullptr, pRoutine, &rq);
    pthread_create(&p3, nullptr, pRoutine, &rq);

    pthread_create(&c1, nullptr, cRoutine, &rq);
    pthread_create(&c2, nullptr, cRoutine, &rq);
    pthread_create(&c3, nullptr, cRoutine, &rq);
    pthread_create(&c4, nullptr, cRoutine, &rq);

    pthread_join(p1, nullptr);
    pthread_join(p2, nullptr);
    pthread_join(p3, nullptr);
    pthread_join(c1, nullptr);
    pthread_join(c2, nullptr);
    pthread_join(c3, nullptr);
    pthread_join(c4, nullptr);
    return 0;
}